/**
 * 玩家操作选项
 */
class ActionItem extends eui.Component {
	private data: PengItem;
	public _3Group: eui.Group;
	public _4Group: eui.Group;

	public constructor(d: PengItem) {
		super();
		this.skinName = "ActionItemSkin";
		this.data = d;
	}
	public childrenCreated(): void {
		this.currentState = this.data.data.length.toString();
		for (let i = 0; i < this.data.data.length; i++) {
			var image = (((this["_" + this.data.data.length + "Group"] as eui.Group).getChildByName(i.toString())) as MyHandCard)
			image.setData(this.data.data[i]);
			image.filters = null;
		}
		this.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTouch, this);
		switch (this.data.type) {
			case MjLogic.Prio.ChiLeft:
				var image = this._3Group.getChildByName("0") as MyHandCard;
				base.Utils.dark(image);
				break;
			case MjLogic.Prio.ChiMiddle:
				var image = this._3Group.getChildByName("1") as MyHandCard;
				base.Utils.dark(image);
				break;
			case MjLogic.Prio.ChiRight:
				var image = this._3Group.getChildByName("2") as MyHandCard;
				base.Utils.dark(image);
				break
		}
	}

	private onTouch(): void {
		console.log(">>> ActionItem onTouch 选择吃牌");
		if (this.data.type == MjLogic.Prio.Gang) {
			WebSocketInstance.getHallSocket().send(CMDConfig.SEND_OPERATE_CARD, { cbOperateCode: this.data.type, cbOperateCard: this.data.data[0] });
		} else {
			WebSocketInstance.getHallSocket().send(CMDConfig.SEND_OPERATE_CARD, { cbOperateCode: this.data.type });
		}
		(this.parent.parent as ActionPanel).visible = false;
		((this.parent.parent as ActionPanel)).itemGroup.visible = false;
		((this.parent.parent as ActionPanel)).buttonGroup.visible = true;
		((this.parent.parent as ActionPanel)).itemGroup.removeChildren();
	}
}